<template>
  <div class="app-container">
    <div class="custom_card_0" v-show="showSearch">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
<!--        <el-form-item label="订单编号" prop="orderNo">-->
<!--          <el-input-->
<!--            v-model="queryParams.orderNo"-->
<!--            placeholder="请输入订单编号"-->
<!--            clearable-->
<!--            size="small"-->
<!--            @keyup.enter.native="handleQuery"-->
<!--          />-->
<!--        </el-form-item>-->
        <el-form-item label="司机名称" prop="driverName">
          <el-input
            v-model="queryParams.driverName"
            placeholder="请输入司机名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <div class="custom_card">
      <el-row class="mb8" :gutter="10">
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="handleQuery"
        ></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="recordsList" stripe
                :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border>
        <template slot="empty">
          <el-empty :image-size="50" description="暂无代驾信息"></el-empty>
        </template>
        <el-table-column label="订单编号" align="center" prop="orderNo"/>
        <el-table-column label="司机名称" align="center" prop="driverName"/>
        <el-table-column label="代驾时长" align="center" prop="drivingDuration">
          <template v-slot="{row}">
            {{row.drivingDuration||'--'}}
          </template>
        </el-table-column>
        <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip>
          <template v-slot="{row}">
            {{row.remark||'--'}}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(scope.row)"
            >编辑
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>

    <!-- 修改代驾时长对话框 -->
    <el-dialog title="编辑代驾时长" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" label-width="80px">
        <el-form-item label="订单号" prop="orderNo">
          <el-input v-model="form.orderNo" disabled/>
        </el-form-item>
        <el-form-item label="代驾时长" prop="drivingDuration">
          <el-input v-model="form.drivingDuration" placeholder="请输入代驾时长"/>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="form.remark" placeholder="请输入备注"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listRecords, updateRecords, exportRecords} from "@/api/bills/records";

export default {
  name: "Records",
  data() {
    return {
      // 遮罩层
      loading: true,
      showSearch: true,
      // 导出遮罩层
      exportLoading: false,
      // 总条数
      total: 0,
      // 司机行驶记录表格数据
      recordsList: [],
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        driverName: null,
      },
      form: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询司机行驶记录列表 */
    getList() {
      this.loading = true;
      listRecords(this.queryParams).then(response => {
        this.recordsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.form = {...row};
      this.open = true;
    },
    /** 提交按钮 */
    submitForm() {
        updateRecords(this.form).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.handleQuery();
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有司机行驶记录数据项？').then(() => {
        this.exportLoading = true;
        return exportRecords(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {
      });
    }
  }
};
</script>
